package chloroform.exec

import chloroform.{InstanceExecutorContext, InstanceExecutor}
import genstream.{OutputResource, InputResource}
import genstream.http.HttpResponseResource
import genstream.pump.Pump

/**
 * Created by IntelliJ IDEA.
 * User: zslajchrt
 * Date: 16.4.11
 * Time: 12:40
 * To change this template use File | Settings | File Templates.
 */

object InputResourceExecutor extends InstanceExecutor {
  def execute(instance: Any, context: InstanceExecutorContext) = {

    if (instance.isInstanceOf[InputResource]) {

      val inputRes: InputResource = instance.asInstanceOf[InputResource]
      val outputRes: OutputResource = new HttpResponseResource(context.response)
      val pump: Pump = new Pump(inputRes, outputRes, closeOutput = false)
      pump.run

    } else
      context.chain.execute

  }
}